package com.jeecms.wicool.dao.share.impl;

import com.google.common.base.Strings;
import com.jeecms.common.hibernate3.Finder;
import com.jeecms.common.hibernate3.HibernateBaseDao;
import com.jeecms.common.hibernate3.Updater;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.share.WealShareDao;
import com.jeecms.wicool.entity.share.WealShare;
import org.springframework.stereotype.Repository;

/**
 * Created by cuiyanlei on 15/6/17.
 */
@Repository
public class WealShareDaoImpl extends HibernateBaseDao<WealShare, Integer> implements WealShareDao {

    @Override
    public WealShare save(WealShare bean) {
        getSession().save(bean);
        return bean;
    }

    @Override
    public WealShare deleteById(Integer id) {
        WealShare bean = get(id);
        getSession().delete(bean);
        return bean;
    }

    @Override
    public WealShare updateByUpdater(Updater<WealShare> updater) {
        return super.updateByUpdater(updater);
    }

    @Override
    public WealShare findById(Integer id) {
        return super.get(id);
    }

    @Override
    public Pagination getPage(String title, String content, Integer pageNo, Integer pageSize) {
        Finder f = Finder.create(" select bean from WealShare bean where 1=1");
        if (!Strings.isNullOrEmpty(title)) {
            f.append(" and bean.title like :title");
            f.setParam("title", "%" + title + "%");
        }

        if (!Strings.isNullOrEmpty(content)) {
            f.append(" and bean.content like :content");
            f.setParam("content", "%" + content + "%");
        }

        f.append(" order by bean.updateTime desc");

        return find(f, pageNo, pageSize);
    }

    @Override
    protected Class<WealShare> getEntityClass() {
        return WealShare.class;
    }
}
